# Maintainer (MSYS2): Michael Hansen <zrax0111@gmail.com>

_variant=-${KF5_VARIANT:-shared}
source "$(dirname ${BASH_SOURCE[0]})"/../mingw-w64-PKGBUILD-common/kde-frameworks5
_kde_f5_init_package "${_variant}" "phonon"
pkgver=4.10.3
pkgrel=1
arch=('any')
pkgdesc="Multimedia framework for KF5 (mingw-w64-qt5${_namesuff})"
url="https://phonon.kde.org"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-extra-cmake-modules")
depends=()
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-qt5${_namesuff}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-glib2"
source=("https://download.kde.org/stable/${_basename}/${pkgver}/${_basename}-${pkgver}.tar.xz"
        'no_absolute_paths.patch')
sha256sums=('2e8b145669afa0e93833e4064b657677abc9413e4007fa5ddc91397c9bddc295'
            '9ee162f8a3440a0ea17aa7937975b98143f4bbff5dd1c5025b0c67c31415bbd5')

prepare() {
  mkdir -p build-${CARCH}${_variant}

  # Phonon hard-codes plugin install paths unnecessarily.  As far as I can
  # tell, the default QPluginLoader search paths should just work as-is.
  cd ${_basename}-${pkgver}
  patch -p1 -i "${srcdir}/no_absolute_paths.patch"
}

build() {
  local -a extra_config
  cd build-${CARCH}${_variant}
  if [ "${_variant}" = "-static" ]; then
    extra_config+=( -DBUILD_SHARED_LIBS=NO )
    QT5_PREFIX=${MINGW_PREFIX}/qt5-static
    export PATH=${QT5_PREFIX}/bin:"$PATH"
  else
    QT5_PREFIX=${MINGW_PREFIX}
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=;-DPHONON_QT_IMPORTS_INSTALL_DIR=;-DPHONON_QT_MKSPECS_INSTALL_DIR=;-DPHONON_QT_PLUGIN_INSTALL_DIR=" \
    cmake ../${_basename}-${pkgver} \
      -DCMAKE_BUILD_TYPE=$(_kde_f5_CMAKE_BUILD_TYPE) \
      -DCMAKE_INSTALL_PREFIX=${QT5_PREFIX} \
      -DPHONON_INSTALL_QT_EXTENSIONS_INTO_SYSTEM_QT=OFF \
      -DPHONON_QT_IMPORTS_INSTALL_DIR=${QT5_PREFIX}/share/qt5/imports \
      -DPHONON_QT_MKSPECS_INSTALL_DIR=${QT5_PREFIX}/share/qt5/mkspecs/modules \
      -DPHONON_QT_PLUGIN_INSTALL_DIR=${QT5_PREFIX}/share/qt5/plugins \
      -DPHONON_BUILD_PHONON4QT5=ON \
      -DBUILD_TESTING=OFF \
      -DECM_DIR=${MINGW_PREFIX}/share/ECM \
      "${extra_config[@]}" \
      -G'MSYS Makefiles'
  make
}

package() {
  cd build-${CARCH}${_variant}
  make DESTDIR="${pkgdir}" install
}
